home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
236_01
/
xc2.c
< prev
next >
Wrap
Text File
|
1989-06-05
|
29KB
|
1,039 lines
/*
HEADER: CUG236;
TITLE: Cross Reference Generator;
DATE: 04/27/1988;
DESCRIPTION: "C-language program cross-referencer, modified for
Microsoft C5.0, with enhancements."
VERSION: 1.1;
KEYWORDS: Cross Reference;
FILENAME: XC2.C;
SEE-ALSO: CUG126, CUG171;
COMPILERS: Vanilla;
AUTHORS: Phillip N. Hisley, David N. Smith, Fred C. Smith,
William C. Colley III;
*/
/**********************************************************
XC - A 'C' Concordance Utility
Version 1.0 January, 1982
Copyright (c) 1982 by Philip N. Hisley
Philip N. Hisley
548H Jamestown Court
Edgewood, Maryland 21040
(301) 679-4606
Released for non-commercial distribution only
Converted to IBM/PC CI/C86 by David N. Smith, May/June 1983
with enhancements and Lattice compiler support in December 1983.
David N. Smith
44 Ole Musket Lane
Danbury, CT 06810
(203) 748-5934
Changes Copyright (c) 1983 by David N. Smith
PC Enhancements include:
1) Nested #INCLUDE statements
2) Single spaced cross-reference list
3) Removal of tabbing on output device
(Since many printers don't support it)
4) #INCLUDE statements with both "--" and <-->
syntax and with a full fileid in the quotes.
5) Multiple input filenames on command line.
Converted to Microsoft C V5.0 with enhancements.
November/December 1987.
Fred C. Smith
20 Whipple Ave.
Stoneham, MA 02180
Enhancements/modifications include:
1) Call to reargv() at beginning of main(). If you are running
Allen Holub's Unix-like shell, reargv() will rebuild argc/argv
to contain the 2kbyte command-line which the shell provides.
If not using that shell, reargv is a no-op. (That shell is
available from M&T Books for around $40, including source!)
2) Modify the include file lookups to use the same algorithm as
used by the Microsoft C compiler, i.e., look first in the
current directory for quote-delimited files. If a complete
pathname is specified look there only then quit. Any remaining
includes, including '<' or '"' delimited ones are then
searched for in the place(s) (if any) specified in the
optional parameter to the -i switch. If not found there,
searches the pathname(s) specified in the INCLUDE environment
variable.
3) Modify the -i switch so that an optional trailing argument
specifies an alternate path for the includes, as in the -I
switch in the Microsoft C compiler's "cl" command. Multiple
-i switches may be given, each with a single pathname. These
multiple pathnames are saved in the order given.
4) Make the default behavior to assume that comments are NOT
nested. Some PC-based C compilers (e.g. Lattice) support
nested comments, but Microsoft's does not. Also, those on
Unix and other larger systems do not. The ANSI standard
does not. For those who prefer to have support for nested
comments, a new command-line switch has been added so that
you can (optionally) have your cake, and eat it, too!
5) Add recognition of keywords recognized in ANSI C, i.e.,
const, enum, signed, volatile, void. Remove recognition of
entry as a keyword (not in ANSI C). Also, add optional
recognition of Microsoft-specific keywords: cdecl, far,
fortran, huge, near and pascal. Use the -m switch for this
last group.
6) Fix the awful kludge which previously existed in xc, in
which struct rf_blk.ref_cnt was declared as an int, but
under certain circumstances was used to hold a pointer to
a struct rf_blk. Replaced the declaration of ref_cnt as
an int with an appropriately declared union of the two
types needed.
7) Minor tweaks to proc_file to fix incorrect line numbers
being generated around included files.
8) In fil_chr(), used ferror() and feof() to implement the
original error-checking logic which had been commented
out in previous versions of the code.
Version 1.1 -- April 1988:
Microsoft-isms removed by William C. Colley, III. In particular
the function access() is not available in many environments. A
reorganization of the code eliminates the use of this function. Note,
however, that the function open_include_file() does chop on file names
which is an inherently non-portable operation, so that function will
have to be cut to fit different operating systems' file naming
conventions. Also, the call to getenv() may have to be modified or
removed.
Also, added the -x option to remove the directories specified in the
INCLUDE environment variable from the search path for #include files.
WCC3.
Abstract:
'XC' is a cross-reference utility for 'C' programs. Its has the
ability to handle nested include files to a depth of 8 levels and
properly processes nested comments as supported by BDS C. Option flags
support the following features:
- Routing of list output to disk
- Cross-referencing of reserved words
- Processing of nested include files
- Generation of listing only
Usage: xc <filename> <flag(s)>
Flags: -i [pathname] = Enable file inclusion
-l = Generate listing only
-m = recognize Microsoft-specific keywords
-n = Allow nested comments
-o <filename> = Write output to named file
-r = Cross-ref reserved words
-w <width> = Maximum listing width
-x = Exclude default include file dir's
Note: For the -i option, the pathname is optional. The -i flag may
be given multiple times, each time with a pathname. These
pathnames are saved, building a list of places to search for
include files. If no list is given the standard places will
be used. If the -i option flag is not used, includes will not
be cross-referenced.
***********************************************************/
/* Compiler specific stuff */
#define LINT_ARGS
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <malloc.h>
#include <string.h>
#undef LINT_ARGS
/* end compiler specific section */
/* Function declarations for xc's routines. */
#include "xc2.h"
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#define DUMMY 0 /* a dummy integer value */
#define ERROR -1
#define MAX_REF 5 /* maximum refs per ref-block */
#define MAX_LEN 20 /* maximum identifier length */
#define MAX_WRD 749 /* maximum number of identifiers */
#define MAX_ALPHA 53 /* maximum alpha chain heads */
#define REFS_PER_LINE 10 /* maximum refs per line */
#define LINES_PER_PAGE 60
#define MAXCOL 78 /* default max column number for listing line */
#define MINCOL 30 /* minimum value for -w option */
#define PATHLEN 128 /* maximum pathname length in chars. */
#define FF 0x0C /* formfeed */
typedef union {
int cnt;
struct rf_blk *pnext;
} cnt;
struct rf_blk {
int ref_item[MAX_REF];
cnt ref_cnt;
} onerf;
struct id_blk {
char id_name[MAX_LEN];
struct id_blk *alpha_lnk;
struct rf_blk *top_lnk;
struct rf_blk *lst_lnk;
} oneid;
struct id_blk *id_vector[MAX_WRD];
struct alpha_hdr {
struct id_blk *alpha_top;
struct id_blk *alpha_lst;
};
struct alpha_hdr alpha_vector[MAX_ALPHA];
int linum; /* line number */
int edtnum = 0; /* edit line number */
int fil_cnt = 0; /* active file index */
int wrd_cnt = 0; /* token count */
int pagno = 0; /* page number */
int id_cnt = 0; /* number of unique identifiers */
int rhsh_cnt = 0; /* number of conflict hits */
int filevl = 0; /* file level */
int paglin = 0; /* page line counter */
int maxcol = MAXCOL; /* maximum right column for listing line */
int prt_ref = FALSE;
char act_fil[PATHLEN];
char lst_fil[PATHLEN];
char gbl_fil[PATHLEN];
char i_path[PATHLEN];
FILE *f_lst_fil;
int n_flg = FALSE;
int i_flg = FALSE;
int o_flg = FALSE;
int r_flg = FALSE;
int l_flg = FALSE;
int m_flg = FALSE;
int x_flg = FALSE;
/*******************************